import React, { Component } from 'react'
import {  Redirect, Route } from 'react-router-dom'
import { getToken } from 'utils/storage'

export default class AuthRoute extends Component {
  render() {
    const {component:Component, ...rest} = this.props
    return (
      <Route {...rest} render={(props)=>{
        // 路由前置守卫
        if(!getToken())return <Redirect 
        to={{
          pathname:'/login',
          // 路径传参 传当前路径
          state:{
            from:props.location.pathname
          }
      }}
        ></Redirect>

        return <Component {...props}></Component>
      }}></Route>
    )
  }
}
